package com.crazyauntzhang.easyshopbackend.service;

import com.crazyauntzhang.easyshopbackend.dao.SupplementFlowDao;
import com.crazyauntzhang.easyshopbackend.domain.SupplementFlow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SupplementFlowService {

	private final SupplementFlowDao supplementFlowDao;

	@Autowired
	public SupplementFlowService(SupplementFlowDao supplementFlowDao) {
		this.supplementFlowDao = supplementFlowDao;
	}

	public void addFlow(String batchNo,
						LocalDateTime batchDateTime,
						String supplierID,
						String itemBarcode,
						Integer operation,
						Double quantity,
						Double purchasePrice,
						String purchaseNo) {
		supplementFlowDao.insertFlow(batchNo, batchDateTime, supplierID, itemBarcode, operation, quantity, purchasePrice, purchaseNo);
		supplementFlowDao.updateStockAndPurchasePrice(itemBarcode, quantity, purchasePrice, operation);
	}

	public SupplementFlow findFlow(String batchNo) {
		return supplementFlowDao.selectFlow(batchNo);
	}

	public SupplementFlow findSpecificFlow(String batchNo, String itemBarcode) {
		return supplementFlowDao.selectSpecificFlow(batchNo, itemBarcode);
	}

	public Double findRestQuantity(String batchNo, String itemBarcode) {
		return supplementFlowDao.selectRestQuantity(batchNo, itemBarcode);
	}

	public List<SupplementFlow> findFlowBySupplierID(String supplierID){
		return supplementFlowDao.findFlowBySupplierID(supplierID);
	}

}
